package com.shm.mostRight;

/**
 * @author SHM
 */
public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     * func getTriggerTime(increase [][]int, requirements [][]int) []int
     * @param increase int整型二维数组 属性增加值
     * @param requirements int整型二维数组 剧情触发要求
     * @return int整型一维数组
     */
    public int[] getTriggerTime (int[][] increase, int[][] requirements) {
        // write code here
        int[] ans = new int[requirements.length];
        for (int i = 1; i < increase.length; i++) {
            increase[i][0] += increase[i-1][0];
            increase[i][1] += increase[i-1][1];
            increase[i][2] += increase[i-1][2];
        }

        for (int i = 0; i < requirements.length; i++) {
            if (requirements[i][0]==0&&requirements[i][1]==0&&requirements[i][2]==0){
                ans[i]=0;
            }else {
                int left = 0;
                int right = increase.length-1;
                if (!(increase[right][0]>=requirements[i][0]&&increase[right][1]>=requirements[i][1]&&increase[right][2]>=requirements[i][2])){
                    ans[i]=-1;
                    continue;
                }
                while (left<right){
                    int mid = (right-left)/2+left;
                    if (!(increase[mid][0]>=requirements[i][0]&&increase[mid][1]>=requirements[i][1]&&increase[mid][2]>=requirements[i][2])){
                        left = mid+1;
                    }else {
                        right = mid;
                    }
                }
                ans[i] = left+1;
            }
        }
        return ans;
    }
}